#!/usr/bin/ruby
# -*- ruby -*-
#
# http://codeforces.com/problemset/problem/400/E

require 'pp'

def process(arr, n = arr.size)
  sum = 0

  n.times do |i|
    (n - i).times do |j|
      sum += arr[j]
      if j < n - i - 1
        arr[j] = arr[j] & arr[j + 1]
      end
    end
  end

  return sum
end

n = nil
m = nil
arr = nil

ARGF.each_with_index do |line, index|
  if n.nil? && m.nil?
    first_line = line.strip.split(' ')
    
    n = first_line.first.to_i
    m = first_line.last.to_i
  elsif arr.nil?
    arr = line.strip.split(' ').map(&:to_i)
  else
    swap_line = line.strip.split(' ')

    i = swap_line.first.to_i
    v = swap_line.last.to_i

    arr[i - 1] = v

    s = process(arr.clone)

    puts s
  end
end
